package com.cloud.Controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: TongRui乀
 * @Date: 2019/10/15 17:02
 * @description：
 */
@RestController
public class WebController {

    @Autowired
    private RestTemplate restTemplate;


    @GetMapping("getService")
    public String getService(){
        return restTemplate.getForObject("http://cloud-service-02-Ribbon/service2", String.class);
    }

    @GetMapping("testHystrix")
    @HystrixCommand(fallbackMethod = "testHystrixFallback")
    public String testHystrix(){

        return this.restTemplate.getForObject("http://cloud-service-02-Ribbon/timeout", String.class);
    }

    public String testHystrixFallback() {
        return "FallBack";
    }

}
